package cn.niit.pm.service.impl;

import cn.niit.pm.dao.AttendanceMapper;
import cn.niit.pm.entity.Attendance;
import cn.niit.pm.service.ServiceInterface;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

/**
 * 考勤管理
 */
@Service
public class AttendanceServiceImpl implements ServiceInterface<Attendance> {

    @Resource
    private AttendanceMapper mapper;

    /**
     *
     * @param attendance 考勤实体类
     * @param pageSize 分页数
     * @param pageNumber 页数
     * @return Attendance
     */
    @Override
    public PageInfo select(Attendance attendance, int pageSize, int pageNumber) {
        //使用PageHelper设置分页，为了安全分页，后边最好紧跟mybatis mapper方法
        //注意这里看起来似乎是属于内存分页，但其实PageHelper插件对mybatis执行流程进行了增强，属于物理分页
        PageHelper.startPage(pageSize, pageNumber);
        List<Attendance> page = mapper.findByPage(attendance);
        PageInfo<Attendance> pageInfo = new PageInfo<>(page);
        return pageInfo;
    }

    @Override
    public void insert(Attendance attendance) {
        mapper.insert(attendance);
    }

    @Override
    public void update(Attendance attendance) {
        mapper.update(attendance);
    }

    @Override
    public void delete(Integer id) {
        mapper.deleteById(id);
    }


    @Override
    public Attendance selectById(Long id) {
        return mapper.selectById(id);
    }
}
